#include "solar/trunk/NinsipidView.h"
#include "tools/Pyscript.h"

NinsipidView::NinsipidView(QWidget *parent) : QPushButton(parent){
    _init_();
}

NinsipidView::NinsipidView(QString text, QWidget *parent): QPushButton(parent){
    _init_();
    doconfigur_text(text);
}

void NinsipidView::_init_(){
    setProperty("lock", false);
    setProperty("win-autowidth", false);
    setProperty("pixmap-margins", 0);
    setProperty("pixmap-drawtype", NT::DRAWTYPE_RECT);
    setProperty("pixmap-imgratio", NT::PIXLOAD_KEEPRATIO);
    setProperty("pixmap-excursion", QPoint(0,0));
    setProperty("bright-drawtype", NT::DRAWTYPE_RECT);
    setProperty("text-align", Qt::AlignVCenter);
    setProperty("text-excursion", QPoint(0,0));
    setProperty("text-font", QFont("KaiTi_GB2312", 11));
    setProperty("text-font-weight", 1);

    setProperty("pixmap-switch-enable", false);
    doconfigur_fontgroup({{MSEVKEY.WIN_NORMAL, QFont("KaiTi_GB2312",13)}});
}

void NinsipidView::doconfigur_adjustedwidth(bool enable){
    setProperty("win-autowidth", enable);
}

void NinsipidView::doconfigur_text(QString text){
    setProperty("view-text", text);
    if (isVisible()) update();
}

void NinsipidView::doconfigur_format(QString format){
    setProperty("view-format", format);
    if (isVisible()) update();
}

void NinsipidView::doconfigur_formattext(QString text){
    setProperty("view-format-text", text);
    if (isVisible()) update();
}

QString NinsipidView::text(){
    return property("view-text").toString();
}

void NinsipidView::doconfigur_textsetting(int align, QFont font, QPoint excursion){
    doconfigur_fontgroup(QMap<QString, QFont>{{MSEVKEY.WIN_CURRENT, font}});
    setProperty("text-excursion", excursion);
    setProperty("text-align", align);
    doconfigur_fontgroup({{MSEVKEY.WIN_NORMAL, font}});
    if (isVisible()) update();
}

void NinsipidView::doconfigur_textsetting(QFont font, QPoint excursion){
    doconfigur_textsetting(property("text-align").toInt(), font, excursion);
}

void NinsipidView::doconfigur_textsetting(QPoint excursion){
    QFont font = property("text-font").value<QFont>();
    doconfigur_textsetting(property("text-align").toInt(), font, excursion);
}

void NinsipidView::doconfigur_color(const QColor &color){
    doconfigur_colorgroup(QMap<QString, QColor>{{MSEVKEY.WIN_NORMAL, color}});
}

void NinsipidView::doconfigur_autoswitch_pixpre(QString pre, QString swt, bool enable){
    QPixmap maskpixmappre;
    PPScriptExec::pyScript_PixmapVariant(QSize(), maskpixmappre, QSize(), true, pre);
    setProperty("pixmap-switch-pre", maskpixmappre);
    QPixmap maskpixmapswt;
    PPScriptExec::pyScript_PixmapVariant(QSize(), maskpixmapswt, QSize(), true, swt);
    setProperty("pixmap-switch-swt", maskpixmapswt);
    setProperty("pixmap-switch-enable", enable);
    setProperty("pixmap-switch-state", true);
    if (isVisible()) pixmapChange(); // disperse to lead
}

void NinsipidView::doconfigur_pixmap(QVariant curtain){
    doconfigur_pixmapgroup({{MSEVKEY.WIN_NORMAL, curtain}});
}

void NinsipidView::doconfigur_fontgroup(QMap<MSEVKEY_STRUCT, QFont> group_font){
    for (int indexof = 0; indexof < msevkeys.length();indexof++){
        QStringList keyList = group_font.keys();
        QString key = msevkeys[indexof];
        if (keyList.contains(key))
        {
            impact_fontgroup[key] = group_font[key];
        } else {
            impact_fontgroup[key] = impact_fontgroup[MSEVKEY.WIN_NORMAL];;
        }
    }
    impact_fontgroup[MSEVKEY.WIN_CURRENT] = impact_fontgroup[MSEVKEY.WIN_NORMAL];
    if (impact_fontgroup[MSEVKEY.WIN_CURRENT] != font()) update();
}

void NinsipidView::doconfigur_colorgroup(QMap<MSEVKEY_STRUCT, QColor> group_color){
    impact_foregroup[MSEVKEY.WIN_NORMAL] = QColor(120,120,120);
    for (int indexof = 0; indexof < msevkeys.length();indexof++)
    {
        QString key = msevkeys[indexof];
        if (group_color[key].isValid())
        {
            impact_foregroup[key] = group_color[key];
        } else {
            impact_foregroup[key] = impact_foregroup[MSEVKEY.WIN_NORMAL];
        }
    }
    impact_foregroup[MSEVKEY.WIN_CURRENT] = impact_foregroup[MSEVKEY.WIN_NORMAL];
}

void NinsipidView::doconfigur_backcolorgroup(QMap<MSEVKEY_STRUCT, QColor> group_bkcolor){
    impact_backgroup[MSEVKEY.WIN_NORMAL] = QColor(Qt::transparent);
    for (int indexof = 0; indexof < msevkeys.length();indexof++)
    {
        QString key = msevkeys[indexof];
        if (group_bkcolor[key].isValid())
        {
            impact_backgroup[key] = group_bkcolor[key];
        } else {
            impact_backgroup[key] = impact_backgroup[MSEVKEY.WIN_NORMAL];
        }
    }
    impact_backgroup[MSEVKEY.WIN_CURRENT] = impact_backgroup[MSEVKEY.WIN_NORMAL];
}

void NinsipidView::doconfigur_bordercolorgroup(QMap<MSEVKEY_STRUCT, QColor> group_border){
    impact_bordgroup[MSEVKEY.WIN_NORMAL] = QColor(Qt::transparent);
    for (int indexof = 0; indexof < msevkeys.length();indexof++)
    {
        QString key = msevkeys[indexof];
        if (group_border[key].isValid())
        {
            impact_bordgroup[key] = group_border[key];
        } else {
            impact_bordgroup[key] = impact_bordgroup[MSEVKEY.WIN_NORMAL];
        }
    }
    impact_bordgroup[MSEVKEY.WIN_CURRENT] = impact_bordgroup[MSEVKEY.WIN_NORMAL];
}

void NinsipidView::doconfigur_pixmapgroup(QMap<MSEVKEY_STRUCT, QVariant> group_pixmap){
    QPixmap maskpixmap;
    maskpixmap.fill(Qt::transparent);
    impact_imaggroup[MSEVKEY.WIN_NORMAL] = maskpixmap;
    int maxpixw = 0;
    for (int indexof = 0; indexof < msevkeys.length();indexof++)
    {
        QString key = msevkeys[indexof];
        QVariant curtain = group_pixmap[key];
        QPixmap draw_pixmap;
        if (!curtain.isNull())
        {
            if (curtain.metaType().id() == QMetaType::QByteArray)
            {
                PPScriptExec::pyScript_PixmapVariant(QSize(), draw_pixmap, QSize(), true, curtain.toByteArray());
            }
            if (curtain.metaType().id() == QMetaType::QString)
            {
                PPScriptExec::pyScript_PixmapVariant(QSize(), draw_pixmap, QSize(), true, curtain.toString());
            }
            else if (curtain.metaType().id() == QMetaType::QPixmap)
            {
                draw_pixmap = curtain.value<QPixmap>();

            }
        }
        if (draw_pixmap.isNull())
        {
            impact_imaggroup[key] = impact_imaggroup[MSEVKEY.WIN_NORMAL];
        }
        else
        {
            impact_imaggroup[key] = draw_pixmap;
        }
        if (impact_imaggroup[key].width() > maxpixw) maxpixw = impact_imaggroup[key].width();
    }
    setMinimumWidth(maxpixw);
    if (isVisible()) pixmapChange(); // disperse to lead
}

void NinsipidView::doconfigur_imgsetting(NT::CST_BRIGHT_SPOT drawtype, NT::WIN_ATTRIBUTE imgratio, int margins, QPoint excursion, bool hi_q){
//*** pixmap error,because keys list not equalily msevkeys and win_current key where not in msevkeys
    QStringList keys = impact_imaggroup.keys();
    int bestw = width() - margins * 2;
    int besth = height() - margins * 2;
    foreach(QString key, keys)
    {
        QPixmap draw_pixmap = impact_imaggroup[key];
        //****不再限制执行条件(auld width != now width:exec)，否则将有可能会漏掉个别图像没有设置尺寸
        if (!draw_pixmap.size().isNull())
        {
            pixmap_ratio(imgratio, draw_pixmap, bestw, besth, hi_q);
            impact_imaggroup[key] = draw_pixmap;
        }
    }
    QVariant prevar = property("pixmap-switch-pre");
    QVariant swtvar = property("pixmap-switch-swt");
    QPixmap prepix = prevar.value<QPixmap>();
    QPixmap swtpix = swtvar.value<QPixmap>();
    if (prevar.isValid() && swtvar.isValid() && !prevar.value<QPixmap>().isNull() && !swtvar.value<QPixmap>().isNull())
    {
            pixmap_ratio(imgratio, prepix, bestw, besth, hi_q);
            pixmap_ratio(imgratio, swtpix, bestw, besth, hi_q);
            setProperty("pixmap-switch-pre", prepix);
            setProperty("pixmap-switch-swt", swtpix);
    }
    if (property("pixmap-switch-enable").toBool() && !prepix.isNull() && !swtpix.isNull())
    {
        impact_imaggroup[MSEVKEY.WIN_CURRENT] = prepix;
    }
    else
    {
        impact_imaggroup[MSEVKEY.WIN_CURRENT] = impact_imaggroup[MSEVKEY.WIN_NORMAL];
    }
    setProperty("pixmap-drawtype", drawtype);
    setProperty("pixmap-imgratio", imgratio);
    setProperty("pixmap-margins", margins);
    setProperty("pixmap-excursion", excursion);
    setProperty("pixmap-hiq", hi_q);
}

void NinsipidView::doconfigur_imgsetting(NT::WIN_ATTRIBUTE imgratio, int margins, QPoint excursion, bool hi_q){
    NT::CST_BRIGHT_SPOT drawtype = static_cast<NT::CST_BRIGHT_SPOT>(property("pixmap-drawtype").toInt());
    doconfigur_imgsetting(drawtype, imgratio, margins, excursion, hi_q);
}

void NinsipidView::doconfigur_imgsetting(int margins, QPoint excursion, bool hi_q){
    NT::CST_BRIGHT_SPOT drawtype = static_cast<NT::CST_BRIGHT_SPOT>(property("pixmap-drawtype").toInt());
    NT::WIN_ATTRIBUTE ratio = static_cast<NT::WIN_ATTRIBUTE>(property("pixmap-imgratio").toInt());
    doconfigur_imgsetting(drawtype, ratio, margins, excursion, hi_q);
}

void NinsipidView::doconfigur_imgsetting(QPoint excursion, bool hi_q){
    NT::CST_BRIGHT_SPOT drawtype = static_cast<NT::CST_BRIGHT_SPOT>(property("pixmap-drawtype").toInt());
    NT::WIN_ATTRIBUTE ratio = static_cast<NT::WIN_ATTRIBUTE>(property("pixmap-imgratio").toInt());
    int margin = property("pixmap-margins").toInt();
    doconfigur_imgsetting(drawtype, ratio, margin, excursion, hi_q);
}

void NinsipidView::doconfigur_imgsetting(bool hi_q){
    NT::CST_BRIGHT_SPOT drawtype = static_cast<NT::CST_BRIGHT_SPOT>(property("pixmap-drawtype").toInt());
    NT::WIN_ATTRIBUTE ratio = static_cast<NT::WIN_ATTRIBUTE>(property("pixmap-imgratio").toInt());
    int margin = property("pixmap-margins").toInt();
    QPoint excursion = property("pixmap-excursion").toPoint();
    doconfigur_imgsetting(drawtype, ratio, margin, excursion, hi_q);
}

void NinsipidView::doconfigur_brighttype(NT::CST_BRIGHT_SPOT drawtype, uint radius, uint border){
    setProperty("bright-drawtype", drawtype);
    setProperty("bright-radius", radius);
    setProperty("bright-border-width", border);
}

bool NinsipidView::doconfigur_lock(bool valid){
    if (valid)
    {
        setProperty("lock", true);
        if (isVisible()) update();
    }
    return property("lock").toBool();
}

void NinsipidView::doconfigur_unlock(){
    setProperty("lock", false);
    if (isVisible()) update();
}

void NinsipidView::mousePressEvent(QMouseEvent *event){
    if (event->button() == Qt::LeftButton)
    {
        emit msev_pre(event);
        emit msnm_pre(objectName());
        setFont(impact_fontgroup[MSEVKEY.WIN_PRESS]);
        impact_foregroup[MSEVKEY.WIN_CURRENT] = impact_foregroup[MSEVKEY.WIN_PRESS];
        impact_backgroup[MSEVKEY.WIN_CURRENT] = impact_backgroup[MSEVKEY.WIN_PRESS];
        impact_bordgroup[MSEVKEY.WIN_CURRENT] = impact_bordgroup[MSEVKEY.WIN_PRESS];
        if (!property("pixmap-switch-enable").toBool()) impact_imaggroup[MSEVKEY.WIN_CURRENT] = impact_imaggroup[MSEVKEY.WIN_PRESS];
    }
    if (event->button() == static_cast<Qt::MouseButton>(property("menu-popue-buttom").toInt()) && !popuMenu->isEmpty())
    {
        popuMenu->popup(mapToGlobal(QPoint(0, height())));
    }
    if (event->button() == Qt::RightButton)
    {
        emit msev_rpre();
    }
    doconfigur_autoswitch_pixswap();
    if (isVisible())update();
    QWidget::mousePressEvent(event);
}

void NinsipidView::doconfigur_autoswitch_pixswap(bool signals_enable){
    QPixmap prepix = property("pixmap-switch-pre").value<QPixmap>();
    QPixmap swtpix = property("pixmap-switch-swt").value<QPixmap>();
    if (property("pixmap-switch-enable").toBool())
    {
        if (property("pixmap-switch-state").toBool())
        {
            impact_imaggroup[MSEVKEY.WIN_CURRENT] = swtpix;
            setProperty("pixmap-switch-state", false);
            if (signals_enable) emit msev_swtc_pre(true);
        }
        else
        {
            impact_imaggroup[MSEVKEY.WIN_CURRENT] = prepix;
            setProperty("pixmap-switch-state", true);
            if (signals_enable) emit msev_swtc_pre(false);
        }
    }
}

void NinsipidView::mouseReleaseEvent(QMouseEvent *event){
    if (event->button() == Qt::LeftButton)
    {
        emit msev_rls(event);
        emit msnm_rls(objectName());
        setFont(impact_fontgroup[MSEVKEY.WIN_RELEASE]);
        impact_foregroup[MSEVKEY.WIN_CURRENT] = impact_foregroup[MSEVKEY.WIN_RELEASE];
        impact_backgroup[MSEVKEY.WIN_CURRENT] = impact_backgroup[MSEVKEY.WIN_RELEASE];
        impact_bordgroup[MSEVKEY.WIN_CURRENT] = impact_bordgroup[MSEVKEY.WIN_RELEASE];
        if (!property("pixmap-switch-enable").toBool()) impact_imaggroup[MSEVKEY.WIN_CURRENT] = impact_imaggroup[MSEVKEY.WIN_RELEASE];
        if (isVisible())update();
    }
    if (event->button() == Qt::RightButton)
    {
        emit msev_rrls();
    }
    QWidget::mouseReleaseEvent(event);
}

void NinsipidView::enterEvent(QEnterEvent *event){
    emit msev_etr(true);
    setFont(impact_fontgroup[MSEVKEY.WIN_ENTER]);
    impact_foregroup[MSEVKEY.WIN_CURRENT] = impact_foregroup[MSEVKEY.WIN_ENTER];
    impact_backgroup[MSEVKEY.WIN_CURRENT] = impact_backgroup[MSEVKEY.WIN_ENTER];
    impact_bordgroup[MSEVKEY.WIN_CURRENT] = impact_bordgroup[MSEVKEY.WIN_ENTER];;
    if (!property("pixmap-switch-enable").toBool()) impact_imaggroup[MSEVKEY.WIN_CURRENT] = impact_imaggroup[MSEVKEY.WIN_ENTER];
    if (isVisible())update();
    QWidget::enterEvent(event);
}

void NinsipidView::leaveEvent(QEvent *event){
    emit msev_etr(false);
    setFont(impact_fontgroup[MSEVKEY.WIN_LEAVE]);
    impact_foregroup[MSEVKEY.WIN_CURRENT] = impact_foregroup[MSEVKEY.WIN_LEAVE];
    impact_backgroup[MSEVKEY.WIN_CURRENT] = impact_backgroup[MSEVKEY.WIN_LEAVE];
    impact_bordgroup[MSEVKEY.WIN_CURRENT] = impact_bordgroup[MSEVKEY.WIN_LEAVE];
    if (!property("pixmap-switch-enable").toBool()) impact_imaggroup[MSEVKEY.WIN_CURRENT] = impact_imaggroup[MSEVKEY.WIN_LEAVE];
    if (isVisible())update();
    QWidget::leaveEvent(event);
}

void NinsipidView::showEvent(QShowEvent *event){
    pixmapChange();
    setFont(impact_fontgroup[MSEVKEY.WIN_CURRENT]);
    if (!width()) setMinimumWidth(23);
    QWidget::showEvent(event);
}

void NinsipidView::pixmapChange(){
    if (!impact_imaggroup.isEmpty())
    {
        int margin = property("pixmap-margins").toInt();
        NT::CST_BRIGHT_SPOT drawtype = static_cast<NT::CST_BRIGHT_SPOT>(property("pixmap-drawtype").toInt());
        NT::WIN_ATTRIBUTE ratio = static_cast<NT::WIN_ATTRIBUTE>(property("pixmap-imgratio").toInt());
        QPoint excursion = property("pixmap-excursion").toPoint();
        doconfigur_imgsetting(drawtype, ratio, margin, excursion);
        update();
    }
}

void NinsipidView::paintEvent(QPaintEvent *event){
    QPainter impactpainter(this);
    impactpainter.setRenderHints(QPainter::SmoothPixmapTransform|
                                 QPainter::Antialiasing);
    QColor draw_fore_color;
    QColor draw_back_color;
    QColor draw_border_color;
    QPixmap draw_pixmap;
    if (property("lock").toBool())
    {
        draw_fore_color =  impact_foregroup[MSEVKEY.WIN_PRESS];
        draw_back_color =  impact_backgroup[MSEVKEY.WIN_PRESS];
        draw_border_color =  impact_bordgroup[MSEVKEY.WIN_PRESS];
        draw_pixmap = impact_imaggroup[MSEVKEY.WIN_PRESS];
    }
    else
    {
        draw_fore_color =  impact_foregroup[MSEVKEY.WIN_CURRENT];
        draw_back_color =  impact_backgroup[MSEVKEY.WIN_CURRENT];
        draw_border_color =  impact_bordgroup[MSEVKEY.WIN_CURRENT];
        draw_pixmap = impact_imaggroup[MSEVKEY.WIN_CURRENT];
    }

    QString view_text = property("view-text").toString();
    QString view_formatt = property("view-format").toString();
    QString view_format_text = property("view-format-text").toString();
    QString draw_text;
    if (!view_formatt.isEmpty())
    {
        if (view_format_text.isEmpty())
        {
            draw_text = view_formatt.remove(QRegularExpression("%\\d{1}"));
        }
        else
        {
            draw_text = view_formatt.arg(view_format_text);
        }
    }
    else
    {
        draw_text = view_text;
    }
    QFontMetrics Metrics(font());
    int size_w = width();
    int size_h = height();
    int character = Metrics.horizontalAdvance(draw_text);
    int text_Left = property("text-excursion").toPoint().x();
    int text_Roof = property("text-excursion").toPoint().y();
    int pix_Left = property("pixmap-excursion").toPoint().x();
    int pix_Roof = property("pixmap-excursion").toPoint().y();
    int borderWidth = property("bright-border-width").toInt();
    int pixmap_width = draw_pixmap.width();
    int pixmap_height = draw_pixmap.height();
    int pixmap_Start_X;
    int pixmap_Start_Y;
    int pixmap_Start_W;
    int pixmap_Start_H;
    int text_start_x;
    int text_start_y;
    int text_start_w;
    int text_start_h;
    NT::CST_BRIGHT_SPOT bright_drawtype = static_cast<NT::CST_BRIGHT_SPOT>(property("bright-drawtype").toInt());
    NT::CST_BRIGHT_SPOT pixmap_drawtype = static_cast<NT::CST_BRIGHT_SPOT>(property("pixmap-drawtype").toInt());
    QRect standarRect(0, 0, size_w, size_h);
    draw_border_color.isValid() ? impactpainter.setPen(QPen(draw_border_color, borderWidth)) :
                                  impactpainter.setPen(QPen(Qt::transparent, borderWidth));
    draw_back_color.isValid() ? impactpainter.setBrush(draw_back_color) :
                                impactpainter.setBrush(Qt::transparent);
    if (bright_drawtype == NT::DRAWTYPE_RECT)
    {
        impactpainter.drawRoundedRect(standarRect,
                                      property("bright-radius").toInt(),
                                      property("bright-radius").toInt());
    }
    else
    {
        standarRect.setWidth(size_h);
        uint radius = size_h / 2;
        impactpainter.drawRoundedRect(standarRect, radius, radius);
    }
    if (!draw_text.isEmpty() &&
        !draw_pixmap.isNull())
    {
        QRect drawTypeRect;
        pixmap_Start_X = pix_Left + (size_h - pixmap_height) / 2;
        pixmap_Start_Y = pix_Roof + (size_h - pixmap_height) / 2;
        pixmap_Start_W = draw_pixmap.width();
        pixmap_Start_H = draw_pixmap.height();
        if (pixmap_drawtype == NT::DRAWTYPE_RECT)
        {
            drawTypeRect.setRect(pixmap_Start_X,
                                 pixmap_Start_Y,
                                 pixmap_Start_W,
                                 pixmap_Start_H);
            impactpainter.drawPixmap(drawTypeRect, draw_pixmap);
        }
        else
        {
            drawTypeRect.setRect(pixmap_Start_X,
                                 pixmap_Start_Y,
                                 draw_pixmap.width(), size_h);

            int RadiusX = size_w / 2;
            int RadiusY = size_h / 2;
            impactpainter.setBrush(draw_pixmap);
            impactpainter.drawRoundedRect(drawTypeRect,
                                          RadiusX,
                                          RadiusY,
                                          Qt::SizeMode::AbsoluteSize);
        }
        impactpainter.setPen(QPen(draw_fore_color));
        impactpainter.setFont(font());
        text_start_x = drawTypeRect.x() + drawTypeRect.width() + text_Left;
        text_start_y = text_Roof;
        text_start_w = size_w - draw_pixmap.width();
        text_start_h = size_h;
        QRect Text_Rect(text_start_x,
                        text_start_y,
                        text_start_w,
                        text_start_h);

        impactpainter.drawText(Text_Rect,
                               static_cast<Qt::Alignment>(property("text-align").toInt()),
                               draw_text);
        if (property("win-autowidth").toBool()) setFixedWidth(text_start_x + character + property("pixmap-margins").toInt() * 2);
    }

    else if (!draw_text.isEmpty() &&
             draw_pixmap.isNull())
    {
        impactpainter.setFont(font());
        impactpainter.setPen(QPen(draw_fore_color));
        text_start_x = text_Left;
        text_start_y = text_Roof;
        text_start_w = size_w;
        text_start_h = size_h;
        QRect Text_Rect(text_start_x,
                        text_start_y,
                        text_start_w,
                        text_start_h);
        impactpainter.drawText(Text_Rect,
                               static_cast<Qt::Alignment>(property("text-align").toInt()),
                               draw_text);

        if (property("win-autowidth").toBool()) setFixedWidth(text_start_x + character);
    }

    else if (draw_text.isEmpty() &&
            !draw_pixmap.isNull())
    {
        pixmap_Start_X =(standarRect.width() - pixmap_width) / 2;
        pixmap_Start_Y = (standarRect.height() - pixmap_height) / 2 ;
        pixmap_Start_W = pixmap_width;
        pixmap_Start_H = pixmap_height;
        QRect pixmapRect(pixmap_Start_X,
                         pixmap_Start_Y,
                         pixmap_Start_W,
                         pixmap_Start_H);
        if (pixmap_drawtype == NT::DRAWTYPE_RECT)
        {
            impactpainter.drawTiledPixmap(pixmapRect, draw_pixmap);
        }
        else
        {
            QPainterPath path;
            path.addRoundedRect(pixmapRect,
                                pixmapRect.width() / 2,
                                pixmapRect.height() / 2);
            impactpainter.setClipPath(path);
            impactpainter.drawPixmap(pixmapRect, draw_pixmap);
        }
        if (property("win-autowidth").toBool()) setFixedWidth(pixmap_Start_W + property("pixmap-margins").toInt() * 2);
    }
    QWidget::paintEvent(event);
}

QMenu* NinsipidView::contentMenu(){
    return popuMenu;
}

void NinsipidView::setFont(const QFont &font){
    doconfigur_fontgroup({{MSEVKEY.WIN_NORMAL, font}});
}

void NinsipidView::doconfigur_popueway(Qt::MouseButton buttom){
    setProperty("menu-popue-buttom", buttom);
}

void NinsipidView::pixmap_ratio(NT::WIN_ATTRIBUTE imgratio, QPixmap &pixmap, int w, int h, bool hi_q){
    switch (imgratio)
    {
        case NT::PIXLOAD_TILEWIN:
            PPScriptExec::pyScript_PixmapVariant(QSize(w, h), pixmap, QSize(-1, -1), hi_q);
            break;
        case NT::PIXLOAD_KEEPRATIO:
            PPScriptExec::pyScript_PixmapVariant(QSize(w, h), pixmap, QSize(-1, h), hi_q);
            break;
        case NT::PIXLOAD_IGNORERATIO_LOWER:
            if (w > h)
            {
                PPScriptExec::pyScript_PixmapVariant(QSize(w, h), pixmap, QSize(h,h), hi_q);
            }
            else
            {
                PPScriptExec::pyScript_PixmapVariant(QSize(w, h), pixmap, QSize(w, h), hi_q);
            }
            break;
        case NT::PIXLOAD_IGNORERATIO_CAPITAL:
            if (w < h)
            {
                PPScriptExec::pyScript_PixmapVariant(QSize(w, h), pixmap, QSize(h,h), hi_q);
            }
            else
            {
                PPScriptExec::pyScript_PixmapVariant(QSize(w, h), pixmap, QSize(w, w), hi_q);
            }
            break;
        default:
            PPScriptExec::pyScript_PixmapVariant(QSize(w, h), pixmap, QSize(0,0), hi_q);
            break;
    }
}
